package com.kfc.order.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Controller;

import com.kfc.order.vo.Customer;
import com.kfc.order.util.BaseUtil;

@Aspect
@Controller
public class PsdAspect {
	private final String loginPc = "execution(* com.kfc.order.service.CustomerManager.login(..))";
	private final String registPc = "execution(* com.kfc.order.service.CustomerManager.regist(..))";

	@Around(loginPc)
	public Object loginMdProcess(ProceedingJoinPoint point){
		Object o = null;
		String passwd = (String) point.getArgs()[1];
		try {
			o = point.proceed(new Object[]{point.getArgs()[0],BaseUtil.Md(passwd, "MD5")});
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return o;
	}
	@Around(registPc)
	public Object registMdProcess(ProceedingJoinPoint point){
		Object o = null;
		Customer c = (Customer)point.getArgs()[0]; 
		c.setCustomerpsd(BaseUtil.Md(c.getCustomerpsd(), "MD5"));
		try {
			o = point.proceed();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return o;
	}


}
